package cn.edu.xhu.library_management.area.mapper;

import cn.edu.xhu.library_management.area.entity.LmBookRack;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: MMJ
 * @Date: 2022 - 08 - 31
 * @Description: 图书架Mapper
 */
public interface BookRackMapper {
    @Select("select * from lm_bookrack where ar_id = #{areaId}")
    @Results(id="BookRackMap",value= {
            @Result(id = true,column = "br_id",property = "id"),
            @Result(column = "br_number",property = "number"),
            @Result(column = "br_row",property = "row"),
            @Result(column = "br_column",property = "column"),
            @Result(column = "br_rowNum",property = "rowNum"),
            @Result(column = "ar_id",property = "areaId")
    })
    public List<LmBookRack> findBookRackByAreaId(Integer areaId);

    /**
     * 通过编号和区域id，查询书架
     * @param number 书架编号
     * @param areaId 区域id
     * @return 书架对象
     */
    @Select("select *from lm_bookrack where br_number=#{number} and ar_id = #{areaId}")
    @ResultMap("BookRackMap")
    LmBookRack findBookRackByNumberAndAreaId(@Param("number") String number, @Param("areaId") Integer areaId);

    @Select("select *from lm_bookrack where br_id = #{id}")
    @ResultMap("BookRackMap")
    LmBookRack findBookRackById(Integer id);
    /**
     * 添加书架
     * @param bookRack 书架对象
     * @return
     */
    @Insert("insert into lm_bookrack(br_number,br_row,br_column,br_rowNum,ar_id)" +
            "values (#{number},#{row},#{column},#{rowNum},#{areaId})")
    public int addBookRack(LmBookRack bookRack);

    public int updateBookRack(LmBookRack bookRack);

    @Delete("delete from lm_bookrack where br_id = #{id} ")
    public int deleteBookRackById(Integer id);



}
